package com.xiaoyang.lotterysystem.dao.mapper;

import com.xiaoyang.lotterysystem.dao.dataobject.Encrypt;
import com.xiaoyang.lotterysystem.dao.dataobject.UserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select count(*) from user where email = #{email}")
    Integer countByMail(@Param("email") String email);

    @Select("select count(*) from user where phone_number = #{phoneNumber}")
    Integer countByPhone(@Param("phoneNumber") Encrypt phoneNumber);

    @Insert("insert into user (user_name, email, phone_number, password, identity)" +
            " values (#{userName}, #{email}, #{phoneNumber}, #{password}, #{identity})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(UserDO userDo);

    @Select("select * from user where email = #{email}")
    UserDO selectByMali(@Param("email") String email);

    @Select("select * from user where phone_number = #{phoneNumber}")
    UserDO selectByPhoneNumber(@Param("phoneNumber") Encrypt phoneNumber);

    List<UserDO> selectUserListByIdentity(@Param("identity") String identity);

    List<Long> selectExistByIds(@Param("items") List<Long> ids);

    List<UserDO> batchSelectByIds(@Param("items") List<Long> ids);
}
